import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { EmployeeService } from './employee.service';
import { CreateEmployeeDto } from './dto/create-employee.dto';
import { UpdateEmployeeDto } from './dto/update-employee.dto';
import { Result } from '../common/dto/common.result';
import { PageEmployeeDto } from './dto/page-employee.dto';

@Controller('employee')
export class EmployeeController {
  constructor(private readonly employeeService: EmployeeService) { }

  @Post('/save')
  async create(@Body() createEmployeeDto: CreateEmployeeDto) {
    await this.employeeService.create(createEmployeeDto);
    return Result.success();
  }

  @Get('/list')
  async findAll() {
    return Result.successData(await this.employeeService.findAll());
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.employeeService.findOne(id));
  }

  @Patch('/info')
  async update(@Body() updateEmployeeDto: UpdateEmployeeDto) {
    await this.employeeService.update(updateEmployeeDto.id, updateEmployeeDto);
    return Result.success();
  }

  @Delete(':id')
  async remove(@Param('id') id: number) {
    await this.employeeService.remove(id);
    return Result.success();
  }

  @Get('/list/page')
  async page(@Body() pageEmployeeDto: PageEmployeeDto) {
    return Result.successData(await this.employeeService.page(pageEmployeeDto));
  }
}
